package com.wj.onlinemusic.mapper;

import com.wj.onlinemusic.model.Music;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface LoveMusicMapper {
    //查询音乐
    @Select("select * from lovemusic where user_id =#{userId} and music_id = #{musicId}")
    Music findLoveMusicByMusicIdAndUserId(Integer userId, Integer musicId);
    //收藏音乐
    @Insert("insert into lovemusic(user_id,music_id) values(#{userId},#{musicId})")
    boolean insertLoveMusic(Integer userId, Integer musicId);

    @Delete("delete from lovemusic where music_id =#{musicId}")
    Integer deleteLoveMusicByMusicId(int musicId);
    @Select("select m.* from lovemusic lm, music m where m.id = lm.music_id and lm.user_id = #{userId}")
    List<Music> findLoveMusicByUserId(int userId);
    @Select("select m.* from lovemusic lm, music m where m.id = lm.music_id and lm.user_id = #{userId}" +
            "and title  like concat('%',#{musicName},'%')")
    List<Music> findLoveMusicBykeyAndUID(String musicName, int userId);
    @Delete("delete from lovemusic where user_id = #{userId} and music_id = #{musicId}")
    int deleteLoveMusic(int userId, int musicId);
}